package logic

import (
	"context"
	"houses_srv/models"

	"houses_srv/houses"
	"houses_srv/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type CheckoutHouseLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewCheckoutHouseLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CheckoutHouseLogic {
	return &CheckoutHouseLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *CheckoutHouseLogic) CheckoutHouse(in *houses.CheckoutHouseRequest) (*houses.CheckoutHouseResponse, error) {
	// todo: add your logic here and delete this line

	var h models.House
	h.ID = uint(in.HouseId)
	err := h.ShowHouse()
	if err != nil {
		return nil, err
	}

	h.Status = 1

	err = h.UpdateHouse()
	if err != nil {
		return nil, err
	}

	return &houses.CheckoutHouseResponse{}, nil
}
